package com.situ.team5.kzq.recruit.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.team5.kzq.recruit.service.EngageResumeService;
import com.situ.team5.kzq.recruit.service.SalaryGrantDetailsService;
import com.situ.team5.pojo.ConfigMajorKind;
import com.situ.team5.pojo.ConfigPublicChar;
import com.situ.team5.pojo.EngageResume;
import com.situ.team5.util.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//简历管理控制层
@Controller
   public class EngageResumeController extends BaseController {
    @Autowired
    EngageResumeService endao;
    @Autowired
    SalaryGrantDetailsService dao;

//简历登记
    @RequestMapping("register")
    public String register(Map map ){
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        //config_public_char国籍查询
        //集合下标是0 开始的
        String[] bb={"国籍","民族","宗教信仰","政治面貌","学历","教育年限","专业","特长","爱好"};
        for(int i=0;i<bb.length;i++){
            List<ConfigPublicChar> configPublicChars = endao.config_public_charSelectGJ(bb[i]);
            map.put("configPublicChars"+i, configPublicChars);


        }
         map.put("configMajorKinds", configMajorKinds);


        return "/page/recruit/resume/register.html";
    }
    @RequestMapping("register_insert")
    public String register_insert(EngageResume e){
         endao.engage_resumeInsert(e);

        return "redirect:register";
    }



    //简历筛选
    @RequestMapping("resume_choose")
    public String resume_choose(Map map){
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        map.put("configMajorKinds",configMajorKinds);
        return "/page/recruit/resume/resume-choose.html";
    }
    //点击开始进入这里进行全查
    @RequestMapping("resume_choose_selectall")
    public String resume_chooseSelectAll(Map map, EngageResume e,
                                         @RequestParam(defaultValue = "1",required = false) Integer startPage,
                                         @RequestParam(defaultValue = "5",required = false) Integer PageSize, HttpSession session){
System.out.println(e);
        if(StringUtils.isEmpty(e)){
            System.out.println("你好");
             e =(EngageResume) session.getAttribute("ee");

        }
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        Map m=new HashMap();
        String sql="select c.major_name,f.major_kind_name,e.* from  engage_resume e inner join config_major c on e.human_major_id=c.major_id inner join config_major_kind f on c.major_kind_id=f.major_kind_id where 1=1\n";
        if(e.getHuman_major_id()!=0){
            sql=sql+" and human_major_id=#{human_major_id}";
            m.put("human_major_id", e.getHuman_major_id());
        }
        if(e.getPpt()!=null &&!"".equals(e.getPpt())){
            sql=sql+" and human_name like #{ppt}";
            m.put("ppt", '%'+e.getPpt()+ '%');
            sql=sql+" or human_history_records like #{ppt}";
            m.put("ppt", '%'+e.getPpt()+ '%');
        }
        if(e.getRegist_timeBegin()!=null){
            sql=sql+" and regist_time > #{getRegist_timeBegin}";
            m.put("getRegist_timeBegin",e.getRegist_timeBegin());
        }
        if(e.getRegist_timeEnd()!=null){
            sql=sql+" and regist_time < #{getRegist_timeEnd}";
            m.put("getRegist_timeEnd", e.getRegist_timeEnd());
        }
        sql=sql+" and check_status=0";
        m.put("sql",sql);
        List<Map> maps = endao.engage_resumeSelectAll(m);
        System.out.println(maps);
        PageInfo pageInfo=new PageInfo(maps, 5); //保存分页信息

        map.put("maps",maps);
        map.put("pageInfo", pageInfo);

        session.setAttribute("ee",e);

        return "/page/recruit/resume/resume-list.html";
    }
    //复核
    @RequestMapping("resume_details")
    public String details( Map map,int id){
        //通过id对简历表进行查询
     Map engagemap= endao.engage_resumeSelectOne(id);
        map.put("pp", engagemap);

        return "/page/recruit/resume/resume-details.html";

    }
    //推荐
    @RequestMapping("kzqtj")
    public String kzqtj(EngageResume e){
        endao.kzqtj(e);

        return "redirect:resume_choose";

        }

    //有效简历查询
    @RequestMapping("valid_resume")
    public String valid_resume(Map map){
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        map.put("configMajorKinds",configMajorKinds);
        return "/page/recruit/resume/valid-resume.html";
    }
    //有效简历全查
    @RequestMapping("valid_list")
    public  String valid_list(Map map,EngageResume e,
                              @RequestParam(defaultValue = "1",required = false) Integer startPage,
                              @RequestParam(defaultValue = "5",required = false) Integer PageSize){
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        Map m=new HashMap();
        String sql="select c.major_name,f.major_kind_name,e.* from  engage_resume e inner join config_major c on e.human_major_id=c.major_id inner join config_major_kind f on c.major_kind_id=f.major_kind_id where 1=1\n";
        if(e.getHuman_major_id()!=0){
            sql=sql+" and human_major_id=#{human_major_id}";
            m.put("human_major_id", e.getHuman_major_id());
        }
        if(e.getPpt()!=null &&!"".equals(e.getPpt())){
            sql=sql+" and human_name like #{ppt}";
            m.put("ppt", '%'+e.getPpt()+ '%');
            sql=sql+" or human_history_records like #{ppt}";
            m.put("ppt", '%'+e.getPpt()+ '%');
        }
        if(e.getRegist_timeBegin()!=null){
            sql=sql+" and regist_time > #{getRegist_timeBegin}";
            m.put("getRegist_timeBegin",e.getRegist_timeBegin());
        }
        if(e.getRegist_timeEnd()!=null){
            sql=sql+" and regist_time < #{getRegist_timeEnd}";
            m.put("getRegist_timeEnd", e.getRegist_timeEnd());
        }
        sql=sql+" and check_status=1";
        m.put("sql",sql);
        List<Map> maps = endao.engage_resumeSelectAll(m);
        System.out.println(maps);
        PageInfo pageInfo=new PageInfo(maps, 5); //保存分页信息

        map.put("maps",maps);
        map.put("pageInfo", pageInfo);
        map.put("ee", e);
        return"/page/recruit/resume/valid-list.html";
    }
    //详情
    @RequestMapping("valid_list_selectOne")
    public String valid_list_selectOne(Map map,int id){
        Map engagemap= endao.engage_resumeSelectOne(id);
        map.put("pp", engagemap);
return "/page/recruit/resume/resume-select.html";

    }

}
